import 'package:flutter/material.dart';
import 'package:path/path.dart';
import '../../spaces/recordspace/record_list.dart';

import '../../helper/Helper.dart';
import '../../helper/cacheHelper.dart';
import '../../helper/global_config.dart';
import '../../helper/routeHelper.dart';
import '../../helper/uidata.dart';
import '../../model/spaceX.dart';
import '../../spaces/spaceX/spacex_details.dart';
import '../../spaces/spaceX/spacex_list.dart';
import '../../widgets/IconWidget.dart';
import '../../widgets/dialogWidget.dart';
import '../../widgets/inputWidget.dart';

class SpaceXHelper {
  static Widget inContainer(Widget child) {
    return Container(
      child: child,
      color: GlobalConfig.cardBackgroundColor,
      padding: EdgeInsets.only(top: 8.0, bottom: 6.0, left: 12.0),
    );
  }

  static Widget SpaceXCard3(BuildContext context, SpaceX record,
      RefreshCallback refrush, Widget lead1) {
    var u1 = CacheHelper.GetUser(record.CreateUser);

    return Column(children: [
      Container(
        padding: EdgeInsets.only(top: 4.0, bottom: 4.0),
        key: Key(record.ID.toString()),
        color: GlobalConfig.cardBackgroundColor,
        child: ListTile(
          onTap: () {
            // RouteHelper.ShowPage(context, SpaceXPage(record));
            RouteHelper.ShowPage(
                context,
                RecordListPage(
                  record.Guid,
                  true,
                  AppBarTitle: record.Title,
                ));
          },
          onLongPress: () {
            showDialog(
              context: context,
              builder: (BuildContext context) {
                if (u1 != null && u1.Guid != record.CreateUser.toLowerCase()) {
                  return DialogWidget.getAlert(context, "提示", "只能删除自己创建的");
                } else {
                  return DialogWidget.getDialog(context, "删除", "点击确定键将删除该条！   ",
                      () async {
                    record.State = -1;
                    await SpaceX.Update(record);
                    refrush();
                  });
                }
              },
            );
          },
          //trailing:Padding(padding: EdgeInsets.only(top:6.0),child:Text(Helper.DateTimeFormat(record.CreateTM))),
          leading: lead1,
          title: Text(record.Title),
        ),
      ),
      InputWidget.getDivider()
    ]);
  }

  static Widget foldIcon() {
    return Icon(
      Icons.folder,
      size: 36.0,
      color: Colors.blue,
    );
  }

  static Widget foldIcon2() {
    return Icon(
      Icons.local_see,
      size: 36.0,
      color: Colors.blue,
    );
  }

  static Widget SpaceCard4(
      BuildContext context, SpaceX record, RefreshCallback refrush) {
    return Column(children: [
      ListTile(
        onTap: () {
          RouteHelper.ShowPage(
              context, SpaceXListPage(record.Guid, record.Title, foldIcon2()));
        },
        onLongPress: () {
          showDialog(
            context: context,
            builder: (BuildContext context) {
              if (UIData.CurrentUser!.Guid.toLowerCase() !=
                  record.CreateUser.toLowerCase()) {
                return DialogWidget.getAlert(context, "提示", "只能删除自己创建的");
              } else {
                return DialogWidget.getDialog(context, "删除", "点击确定键将删除该条！",
                    () async {
                  record.State = -1;
                  await SpaceX.Update(record);
                  //SpaceX.Delete(record);
                  refrush();
                });
              }
            },
          );
        },
        //subtitle:Padding(padding: EdgeInsets.only(top:6.0),child:Text(Helper.DateTimeFormat(record.CreateTM))),
        leading: foldIcon(),
        title: Text(record.Title),
        tileColor: Colors.white,
      ),
      InputWidget.getDivider()
    ]);
  }
}
